package com.huc.rabbit.mq.consumer;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class IngateConsumer {

//    @RabbitHandler
    @RabbitListener(queues = {"mq.ingate.queue"})
    public void process(String msg, Channel channel, Message message) throws IOException {
        System.out.println("收到消息:" + msg);
        try {
//            int i = 10/0;
            System.out.println("确认消费进闸支付消息 :" + msg);
            //手动ack机制
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (Exception e) {
            System.out.println("进闸支付入库异常:" + e);
            channel.basicNack(message.getMessageProperties().getDeliveryTag(),false,true);
        }
    }

}
